﻿Imports System.Data.SqlClient

Public Class frmPOSMenuSetup

    Private Sub frmBPList_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.lblCaption.Text = "QC SETUP"
        Dim cn As SqlConnection = Nothing
        cn = Functions.SAP_Local_OpenSQLConnection()
        _MenuTableAdapter.Connection = cn
        _MenuDetailTableAdapter.Connection = cn
        Me._MenuTableAdapter.Fill(Me.SAP_YGNDataSet._Menu)
    End Sub
    Private Sub GridMenu_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GridMenu.SelectionChanged
        Dim MenuCode As Integer
        If Not IsNothing(GridMenu.CurrentRow) Then
            MenuCode = GridMenu.GetValue("Menu_Code")
            Me._MenuDetailTableAdapter.Fill(Me.SAP_YGNDataSet._MenuDetail, MenuCode)
        End If
    End Sub
    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Try
            Dim ret As String = Save()
            If ret <> "" Then
                MessageBox.Show(ret)
            Else
                MessageBox.Show("Operation completed!")
            End If

        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub

    Private Sub GridMenuDetail_ColumnButtonClick(ByVal sender As System.Object, ByVal e As Janus.Windows.GridEX.ColumnActionEventArgs) Handles GridMenuDetail.ColumnButtonClick
        Dim ret As String = Save()
        If ret <> "" Then
            MessageBox.Show(ret)
        Else
            Dim MenuCode As Integer
            If Not IsNothing(GridMenu.CurrentRow) Then
                MenuCode = GridMenu.GetValue("Menu_Code")

                Dim frm As New frmGeneralList
                frm.QueryStr = "select ItemCode,ItemName from OITM where SellItem='Y'"
                If frm.ShowDialog = Windows.Forms.DialogResult.OK Then
                    For Each row As Janus.Windows.GridEX.GridEXSelectedItem In frm.GridStep1.SelectedItems
                        GridMenuDetail.SetValue("Item_Code", row.GetRow.Cells.Item("ItemCode").Value.ToString)
                        GridMenuDetail.SetValue("Item_Name", row.GetRow.Cells.Item("ItemName").Value.ToString)
                        GridMenuDetail.SetValue("MENU_Code", MenuCode)
                        GridMenuDetail.UpdateData()

                        GridMenuDetail.Row = GridMenuDetail.RowCount - 1
                    Next
                End If

            End If

            
        End If
    End Sub

    Private Function Save() As String
        Try
            GridMenu.UpdateData()
            _MenuTableAdapter.Update(SAP_YGNDataSet)
            _MenuDetailTableAdapter.Update(SAP_YGNDataSet)
            SAP_YGNDataSet.AcceptChanges()
            Return ""
        Catch ex As Exception
            Return ex.ToString
        End Try
    End Function
End Class
